package com.ruoyi.sys.vehile.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.vehile.domain.TbRecordCharging;
import com.ruoyi.sys.vehile.service.ITbRecordChargingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 记录充电Controller
 *
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/system/charging")
public class TbRecordChargingController extends BaseController
{
    @Autowired
    private ITbRecordChargingService tbRecordChargingService;

    /**
     * 查询记录充电列表
     */
    @PreAuthorize("@ss.hasPermi('system:charging:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbRecordCharging tbRecordCharging)
    {
        startPage();
        List<TbRecordCharging> list = tbRecordChargingService.selectTbRecordChargingList(tbRecordCharging);
        return getDataTable(list);
    }

    /**
     * 导出记录充电列表
     */
    @PreAuthorize("@ss.hasPermi('system:charging:export')")
    @Log(title = "记录充电", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRecordCharging tbRecordCharging)
    {
        List<TbRecordCharging> list = tbRecordChargingService.selectTbRecordChargingList(tbRecordCharging);
        ExcelUtil<TbRecordCharging> util = new ExcelUtil<TbRecordCharging>(TbRecordCharging.class);
        util.exportExcel(response, list, "记录充电数据");
    }

    /**
     * 获取记录充电详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:charging:query')")
    @GetMapping(value = "/{rcId}")
    public AjaxResult getInfo(@PathVariable("rcId") Long rcId)
    {
        return AjaxResult.success(tbRecordChargingService.selectTbRecordChargingByRcId(rcId));
    }

    /**
     * 新增记录充电
     */
    @PreAuthorize("@ss.hasPermi('system:charging:add')")
    @Log(title = "记录充电", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRecordCharging tbRecordCharging)
    {
        return toAjax(tbRecordChargingService.insertTbRecordCharging(tbRecordCharging));
    }

    /**
     * 修改记录充电
     */
    @PreAuthorize("@ss.hasPermi('system:charging:edit')")
    @Log(title = "记录充电", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRecordCharging tbRecordCharging)
    {
        return toAjax(tbRecordChargingService.updateTbRecordCharging(tbRecordCharging));
    }

    /**
     * 删除记录充电
     */
    @PreAuthorize("@ss.hasPermi('system:charging:remove')")
    @Log(title = "记录充电", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rcIds}")
    public AjaxResult remove(@PathVariable Long[] rcIds)
    {
        return toAjax(tbRecordChargingService.deleteTbRecordChargingByRcIds(rcIds));
    }
}
